import Vue from 'vue'
import VueRouter from 'vue-router'


const Home = () => import('@/views/home/Home.vue')
const Cart = () => import('@/views/cart/Cart.vue')
const Profile = () => import('@/views/profile/Profile.vue')
const Category = () => import('@/views/category/Category.vue')
const Detail = () => import('@/views/detail/Detail.vue')
const Login = () => import('@/components/common/login/index/Login.vue')

Vue.use(VueRouter)

const routes = [
  {
    path: '',
    meta: { title: '登录' , isLogin: true},
    redirect: '/login'
  },
  {
    path: '/login',
    meta: { title: '登录', isLogin: true},
    component: Login
  },
  {
    path: '/home',
    meta: { title: '首页' },     
    component: Home
  },
  {
    path: '/category',
    meta: { title: '收藏' },
    component: Category
  },
  {
    path: '/cart',
    meta: { title: '购物车' },
    component: Cart
  },
  {
    path: '/profile',
    meta: { title: '我的' },
    component: Profile
  },
  {
    path: '/detail/:iid', // 动态路由 按需传参数
    meta: { title: '商品详情' },
    component: Detail
  }
]


// 这里导入新的路由 实现路由懒加载
const router = new VueRouter({
  mode: 'hash',
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()
})

export default router
